package com.hjb.service.impl.app;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hjb.service.app.InstalmentOrderService;
import com.hjb.service.domain.InstalmentOrder.InstalmentOrder;
import com.hjb.service.mapper.InstalmentOrderMapper;

import tk.mybatis.mapper.entity.Example;

@Service
public class InstalmentOrderServiceImpl implements InstalmentOrderService {
	@Autowired
	private InstalmentOrderMapper instalmentOrderMapper;
	
	/*
	 * 保存分期订单
	 */
	@Override
	public void saveOrder(InstalmentOrder instalmentOrder) {
		instalmentOrderMapper.insert(instalmentOrder);
	}

	/*
	 * 根据合同订单查询分期订单列表
	 */
	@Override
	public List<InstalmentOrder> getOrderList(String siteUserOrderId) {
		Example example = new Example(InstalmentOrder.class);
		example.createCriteria().andEqualTo("orderId", siteUserOrderId);
		return instalmentOrderMapper.selectByExample(example);
	}

	/*
	 * 根据订单号和期数更新分期订单
	 */
	@Override
	public int updateByOrderIdAndTerm(InstalmentOrder instalmentOrder) {
		Example example = new Example(InstalmentOrder.class);
		example.createCriteria().andEqualTo("orderId", instalmentOrder.getOrderId()).andEqualTo("termNo",instalmentOrder.getTermNo());
		return instalmentOrderMapper.updateByExampleSelective(instalmentOrder, example);
	}

	/* 
	 * 根据合同订单号删除全部分期订单
	 */
	@Override
	public void delete(String siteUserOrderId) {
		Example example = new Example(InstalmentOrder.class);
		example.createCriteria().andEqualTo("orderId", siteUserOrderId);
		instalmentOrderMapper.deleteByExample(example);
	}

}
